/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.study.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.study.entity.StudyData;
import com.jeesite.modules.study.service.StudyDataService;

/**
 * 学习信息表Controller
 * @author wk
 * @version 2020-11-26
 */
@Controller
@RequestMapping(value = "${adminPath}/study/studyData")
public class StudyDataController extends BaseController {

	@Autowired
	private StudyDataService studyDataService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public StudyData get(String id, boolean isNewRecord) {
		return studyDataService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("study:studyData:view")
	@RequestMapping(value = {"list", ""})
	public String list(StudyData studyData, Model model) {
		model.addAttribute("studyData", studyData);
		return "modules/study/studyDataList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("study:studyData:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<StudyData> listData(StudyData studyData, HttpServletRequest request, HttpServletResponse response) {
		studyData.setPage(new Page<>(request, response));
		Page<StudyData> page = studyDataService.findPage(studyData);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("study:studyData:view")
	@RequestMapping(value = "form")
	public String form(StudyData studyData, Model model) {
		model.addAttribute("studyData", studyData);
		return "modules/study/studyDataForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("study:studyData:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated StudyData studyData) {
		studyDataService.save(studyData);
		return renderResult(Global.TRUE, text("保存学习信息表成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("study:studyData:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(StudyData studyData) {
		studyDataService.delete(studyData);
		return renderResult(Global.TRUE, text("删除学习信息表成功！"));
	}
	
}